<?php

namespace common\models;

use Yii;
use yii\helpers\ArrayHelper;
use \common\models\base\Character as BaseCharacter;

/**
 * This is the model class for table "character".
 */
class Character extends BaseCharacter
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return array_replace_recursive(parent::rules(),
	    [
            [['created_at', 'updated_at', 'deleted_at','name','id'], 'safe'],
            [['id', 'created_by', 'updated_by', 'deleted_by'], 'string', 'max' => 32],
            [['status'], 'string', 'max' => 2]
        ]);
    }

    //返回权限名称
    protected $_authorityName = '';

    /**
     * @return string
     */
    public function getAuthorityName()
    {
        if (!$this->_authorityName) {
            $this->_authorityName = $this->authorities?ArrayHelper::index($this->authorities,null,'views'):'';
        }
        return $this->_authorityName;
    }

    public function getSummitInformation()
    {
        return $this->hasMany(SummitInformation::className(),['view'=>'views'])->viaTable('authority',['character_id'=>'id']);
    }
}
